import { Tools } from 'weaver-mobile';
import base from '../util/base';

const callApi = (url, method, params, type="json") =>{
	params.isMobileForm = "1";
	return Tools.callApi({url, method, params, type});
}

const appendAuthParams = (params) =>{
	const { commonParam } = base.wfGlobalStore;
	const arr = ["authStr", "authSignatureStr"];
	arr.map(key =>{
		if(!(key in params) && key in commonParam)
			params[key] = commonParam[key];
	});
}

const appendUserParams = (params) =>{
	const { commonParam } = base.wfGlobalStore;
	const arr = ["wfTestStr", "f_weaver_belongto_userid", "f_weaver_belongto_usertype"];
	arr.map(key =>{
		if(!(key in params) && key in commonParam)
			params[key] = commonParam[key];
	});
}


//表单加载基础信息
export const loadBaseInfo = params => {
	return callApi('/api/workflow/reqform/loadForm', 'POST', params);
}

//明细数据
export const loadDetailData = params => {
	return callApi('/api/workflow/reqform/detailData', 'POST', params);
}

//明细数据keyid
export const getDetailDataKeyIds = params => {
    return callApi('/api/workflow/reqform/detailDataKeyId', 'POST', params);
}

//改变明细分页条数
export const saveDetailPaging = params => {
	return callApi('/api/workflow/reqform/saveDetailPaging', 'POST', params);
}

//签字意见列表
export const loadRequestLog = params => {
	return callApi('/api/workflow/reqform/requestLog', 'POST', params);
}

//加载签字意见基本信息
export  const getRequestLogBaseInfo = params => {
    return callApi('/api/workflow/reqform/getRequestLogBaseInfo', 'POST', params);
}

//加载签字意见列表数据
export  const getRequestLogList = params => {
    return callApi('/api/workflow/reqform/getRequestLogList', 'POST', params);
}

//更新意见列表分页
export const updateRequestLogPageSize = params => {
	return callApi('/api/workflow/reqform/updateRequestLogPageSize', 'POST', params);
}

//意见输入框
export const getSignInput = params => {
	appendAuthParams(params);
	return callApi('/api/workflow/reqform/signInput', 'POST', params);
}

//右键按钮
export const getRightMenu = params => {
	return callApi('/api/workflow/reqform/rightMenu', 'POST', params);
}

//请求状态更新(已读等)
export const updateReqInfo = params => {
	return callApi('/api/workflow/reqform/updateReqInfo', 'POST', params);
}

//加载代码块
export const loadScriptContent = params => {
	return callApi('/api/workflow/reqform/scripts', 'GET', params,'text');
}

//加载custompage
export const loadCustompage = (address, params) => {
	params["__address__"] = address;
	return callApi('/workflow/request/CustomPageForward.jsp', 'POST', params, 'text');
}

//加载自定义开发文件列表
export const loadInjectDevFile = (params) => {
	return callApi('/api/workflow/injectDev/loadFormDevFileList', 'POST', params);
}

//text方式加载指定路径内容
export const loadHrefTextContent = (address, params) => {
	return callApi(address, 'GET', params, 'text');
}

//判断退回方式
export const judgeRejectWay = params => {
	return callApi('/api/workflow/reqform/judgeRejectWay', 'POST', params);
}

//加载流程状态
export const getWfStatus = params => {
	appendAuthParams(params);
	return callApi('/api/workflow/reqform/wfstatusnew', 'POST', params);
}

//加载流程状态计数
export const getWfStatusCount = params => {
	appendAuthParams(params);
	return callApi('/api/workflow/reqform/wfstatuscount', 'POST', params);
}

//加载相关资源
export const getResourcesKey = params => {
	return callApi('/api/workflow/reqform/resources', 'GET', params);
}

//字段联动接口
export const reqDataInputResult = params => {
	return callApi('/api/workflow/linkage/reqDataInputResult', 'POST', params);
}

//SQL联动接口
export const reqFieldSqlResult = params => {
	appendUserParams(params);
	return callApi('/api/workflow/linkage/reqFieldSqlResult', 'POST', params);
}

//日期时间计算接口
export const reqDateTimeResult = params => {
	return callApi('/api/workflow/linkage/reqDateTimeResult', 'POST', params);
}

//生成流程编号
export const createWfCode = params => {
	return callApi('/api/workflow/reqform/createWfCode','POST',params);
}

export const loadWfCodeFieldValueInfo = params => {
	return callApi('/api/workflow/reqform/loadWfCodeFieldValueInfo','POST',params);
}

export const functionLink = params => {
	return callApi('/api/workflow/reqform/functionLink','POST',params);
}

export const reqOperate = (actionType,params) => {
	return callApi('/api/workflow/reqform/'+actionType,'POST',params);
}
export const triggerSubWf = (params) => {
	return callApi('/api/workflow/reqform/triggerSubWf','POST',params);
}
export const getUploadFileInfo = (params) => {
	return callApi('/api/workflow/reqform/getUploadFileInfo','POST',params);
}
export const requestImport = (params) => {
	return callApi('/api/workflow/reqform/requestImport','POST',params);
}

export const getReqInterventionInfo = (params) => {
	return callApi('/api/workflow/monitor/intervention','POST',params);
}

export const getInterventionUser = (params) => {
	return callApi('/api/workflow/monitor/getUsers','POST',params);
}

//异常处理选择操作者
export const chooseExceptionOperator = (params) => {
	return callApi('/api/workflow/reqform/chooseExceptionOperator','POST',params);
}

//超时设置
export const overTimeSetting = (params) => {
	return callApi('/api/workflow/reqform/overTimeSetting','POST',params);
}

//自由流转读取数据
export const freeFlowRead = (params) => {
	return callApi('/api/workflow/reqform/freeFlowRead','POST',params);
}

//自由流转保存数据
export const freeFlowSave = (params) => {
	return callApi('/api/workflow/reqform/freeFlowSave','POST',params);
}

//流程编辑锁定相关操作
export const editLockOper = (params) => {
	return callApi('/api/workflow/reqform/editLockOper','POST',params);
}

//转发提交
export const forwardSubmit = (params) => {
    return callApi('/api/workflow/reqform/remarkOperate','POST',params);
}
//转发提交
export const getReqAtUser = (params) => {
    return callApi('/api/workflow/forward/getReqWfNodeOperators','GET',params);
}

//请假类型浏览框数据接口
export const getLeaveBrowserOptions = params => {
	return callApi('/api/public/browser/data/34', 'GET', params);
}

//语音、全文批注附件保存
export const saveMobileSignAnnex = params => {
	return callApi('/api/workflow/reqform/saveMobileSignAnnex', 'post', params);
}

//根据部门 分部 公共组获取转发接收人信息
export const loadForwardResources = (params) => {
    return callApi('/api/workflow/forward/getForwardOrgResource', 'GET', params);
}

//新版公式
export const getFormulasNew = params => {
    return callApi('/api/workflow/formula/getFormulas', 'POST', params);
}
//紧急程度数据
export const getleveldata = params => {
    return callApi('/api/workflow/index/getCustomLevelList', 'POST', params);
}

//流程收回（监控中）
export const doMonitorRB = params => {
	return callApi('/api/workflow/monitor/repossessed', 'POST', params);
}

//流程删除（监控中）
export const doMonitorDel = params => {
	return callApi('/api/workflow/monitor/delete', 'POST', params);
}

//确认流程提醒人
export const getRemindData = params => {
	return callApi('/api/workflow/reqform/getRemindData', 'GET', params);
}

//触发流程提醒
export const doRemind = params => {
	return callApi('/api/workflow/reqform/doRemind', 'POST', params);
}

//此接口由SAP模块提供，将浏览按钮选中数据转换为流程识别的数据
export const convertSapDatas = params => {
	return callApi('/api/SapIntegration/browser/assignToBill', 'POST', params);
}

//意见征询收回
export const doTakeBack = params => {
    return callApi('/api/workflow/reqform/doTakeBack', 'POST', params);
}

//结束意见征询
export const doTakEnd = (params={})=>{
	return callApi('/api/workflow/reqform/doTakEnd', 'POST', params);
}

//获取自定义操作菜单
export const getCustomOperation = params => {
	return callApi('/api/workflow/reqform/getCustomOperation', 'POST', params);
}

//获取自定义操作菜单
export const runCustomOperationAction = params => {
	return callApi('/api/workflow/reqform/runCustomOperationAction', 'GET', params);
}

//分享按钮是否显示
export const isShowShareBtn = () => {
	return callApi('/api/systeminfo/appsetting/get', 'GET', {});
}

//是否显示签批按钮
export const getMobileWFOffice = () => {
	return callApi('/api/odoc/officialSettings/getMobileWFOffice', 'POST', {});
}

//获取转发批注是否提醒选项信息
export const getReplyNoticeInfo = (params) => {
	return callApi('/api/workflow/forward/getReplyNoticeInfo','GET',params);
}
// 判断是否接入EM
export const checkJoin = () => {
	return callApi('/api/ec/dev/app/checkJoin','GET',{});
}
//获取提醒设置
export const loadRemindInfo = (params) => {
  return callApi('/api/workflow/forward/loadRemindInfo', 'GET', params);
}

//加签简易模式
export const getTransferCondition = (params={}) => {
	return callApi('/api/workflow/reqform/getTransferCondition', 'POST',params);
}
//智能预测流程图获取操作者信息
export const getForecastInfo = (params) => {
  return callApi('/api/workflow/layout/getForecastInfo', 'POST', params);
}

//转发、意见征询、转办范围设置信息
export const getFwLimitBrowserSet = (params) => {
    return callApi('/api/workflow/fwLimit/getFwLimitBrowserSet','GET',params);
}
  
//修改流程共享权限
export const addshare = (params)=>{
	return callApi('/api/common/chatResource/addshare','POST',params);
}

//流程撤回
export const requestWithDraw = (params) => {
	return callApi('/api/workflow/reqform/requestWithdraw','POST',params);
}

//获取连续处理信息
export const getContinnuationProcessInfo = params =>{
	return callApi('/api/workflow/reqlist/continnuationProcessInfo','POST',params);
}


//获取流程表单自定义tab
export const getFormTab = params =>{
	return callApi('/api/workflow/reqform/getFormTab','POST',params);
}

//删除文档
export const deleteDoc = params =>{
	return callApi('/api/doc/operate/delete', 'GET', params);
}

//获取发票云token
export const getInvoiceCloudToken = params =>{
	return callApi('/api/fna/fnaEmbileMicroReport/getInvoiceCloudToken', 'GET', params);
}